<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    li {
      list-style: none;
    }

    html,
    body,
    #box {
      width: 100%;
      height: 100%;
    }

    #box {
      background-color: #eee;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

    .footer {
      width: 100%;
      height: 40px;
      background-color: skyblue;
      display: flex;
      justify-content: space-around;
      line-height: 40px;
    }

    .content {
      width: 100%;
      flex: 1;
      background-color: orange;
    }
  </style>
</head>

<body>
  <div id="box">
    <div class="content">
      <!-- 这是页面内容的容器 -->

    </div>
    <ul class="footer">
      <li><a href="#/home">首页</a></li>
      <li><a href="#/goodstype">商品分类</a></li>
      <li><a href="#/car">购物车</a></li>
      <li><a href="#/collection">收藏</a></li>
      <li><a href="#/my">我的</a></li>
      <li><a href="#/my">我的</a></li>
    </ul>
  </div>

  <script src="./js/home.js"></script>
  <script src="./js/goodstype.js"></script>
  <script src="./js/car.js"></script>
  <script src="./js/my.js"></script>
  <script src="./js/collection.js"></script>

  <script>

    // 开闭原则：
    //  对扩展（非逻辑代码，如：配置项）开放。  
    //  对修改（逻辑代码）关闭。
    

    window.onhashchange = function () {
      // console.log("hash变了",location.hash);
      let div = document.querySelector(".content");
      
      // switch (location.hash) {
      //   case "#/home": div.innerHTML = home; break;
      //   case "#/goodstype": div.innerHTML = goodstype; break;
      //   case "#/car": div.innerHTML = car; break;
      //   case "#/collection": div.innerHTML = collection; break;
      //   case "#/my": div.innerHTML = my; break;
      // }

        let obj = {
          "#/home":home,
          "#/goodstype":goodstype,
          "#/car":car,
          "#/collection":collection,
          "#/my":my
        }

        div.innerHTML = obj[location.hash];

    }

  </script>
</body>

</html>